package cn.HL.basic.controller;

import cn.HL.basic.dto.RegisterDto;
import cn.HL.basic.service.IVerifyCodeService;
import cn.HL.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 发送验证
 * 1.图片验证
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 图片验证
     * @param key
     * @return
     */
    @GetMapping("/image/{key}")
    public AjaxResult image(@PathVariable("key") String key){
        try {
            String image = verifyCodeService.image(key);
            return AjaxResult.me().setResultObj(image);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("生成错了！"+e.getMessage());
        }
    }
    /**
     * 手机验证码
     *
     * @return
     * /verifyCode/smsCode
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody RegisterDto dto ){
        try {
            verifyCodeService.smsCode(dto);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("出错了!!！"+e.getMessage());
        }
    }

}
